package com.ruoyi.serviceimpl;

import com.ruoyi.mapper.OrderMapper;
import com.ruoyi.pojo.Balance;
import com.ruoyi.pojo.Goods;
import com.ruoyi.pojo.Order;
import com.ruoyi.service.BalanceService;
import com.ruoyi.service.GoodsService;
import com.ruoyi.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.math.BigDecimal;

//@DubboService
@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;
    /**
     * 用户余额接口服务
     */
    @DubboReference()
    private BalanceService balanceService;
    /**
     * 商品接口服务
     */
    @DubboReference()
    private GoodsService goodsServiceImpl;

    @GlobalTransactional
    @Override
    public void inserOrder(Order order) {
        //创建订单信息
        orderMapper.insert(order);
        //扣减用户余额信息
        balanceService.updateBalance(new Balance(1,1,new BigDecimal(100),new BigDecimal(1)));
        //扣减商品库存信息
        goodsServiceImpl.updateGoods(new Goods(1,1));
    }
}
